package com.thunisoft.design.singleton;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @title SerializeClient.java
 * @package com.thunisoft.design.singleton
 * @projectName spring.boot
 * @author yzj
 * @date 2020年5月22日 下午3:21:47
 */
public class SerializeClient {
	public static void main(String[] args) {
		LazyInnerClassSingleton s1 = null;
		LazyInnerClassSingleton s2 = LazyInnerClassSingleton.getInstance();

		FileOutputStream fos = null;
		try {

			fos = new FileOutputStream("SeriableSingleton.obj");
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(s2);
			oos.flush();
			oos.close();

			FileInputStream fis = new FileInputStream("SeriableSingleton.obj");
			ObjectInputStream ois = new ObjectInputStream(fis);
			s1 = (LazyInnerClassSingleton) ois.readObject();
			ois.close();

			s1.print();
			s2.print();
			System.out.println(s1 == s2);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
